<template>
    <div class="default-main ba-table-box">
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />

        <!-- 表格顶部菜单 -->
        <TableHeader
            :buttons="['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']"
            :quick-search-placeholder="t('quick Search Placeholder', { fields: t('visit.quick Search Fields') })"
        />

        <!-- 表格 -->
        <!-- 要使用`el-table`组件原有的属性，直接加在Table标签上即可 -->
        <Table ref="tableRef" />

        <!-- 表单 -->
        <PopupForm />
    </div>
</template>

<script setup lang="ts">
import { ref, provide, onMounted } from 'vue'
import baTableClass from '/@/utils/baTable'
import { visit } from '/@/api/controllerUrls'
import { defaultOptButtons } from '/@/components/table'
import { baTableApi } from '/@/api/common'
import { useI18n } from 'vue-i18n'
import PopupForm from './popupForm.vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'

const { t } = useI18n()
const tableRef = ref()
const optButtons = defaultOptButtons(["edit","delete"])
const baTable = new baTableClass(
    new baTableApi(visit),
    {
        pk: 'VISITID',
        column: [
            { type: 'selection', align: 'center', operator: false },
            // { label: t('visit.VISITID'), prop: 'VISITID', align: 'center', operator: 'RANGE' },
            { label: t('visit.CORPID'), prop: 'CORPID', align: 'center' },
            { label: t('visit.CORPMAN'), prop: 'CORPMAN', align: 'center',operator:false },
            { label: t('visit.SALER'), prop: 'SALER', align: 'center',operator:false  },
            // 拜访时间
            { label: t('visit.VISITDT'), prop: 'VISITDT', align: 'center', render: 'datetime', sortable: 'custom', operator: 'RANGE', width: 160 },
            { label: t('visit.DETAIL'), prop: 'OP', align: 'center'},

            { label: t('visit.OP'), prop: 'OP', align: 'center',show:false ,operator:false },
            { label: t('visit.OPTIME'), prop: 'OPTIME', align: 'center', render: 'datetime', sortable: 'custom', operator: 'RANGE', width: 160,show:false ,operator:false },
            { label: t('visit.POSITION'), prop: 'POSITION', align: 'center',show:false,operator:false },
            { label: t('visit.CORPNAME'), prop: 'CORPNAME', align: 'center',show:false,operator:false  },
            { label: t('visit.ENAME'), prop: 'ENAME', align: 'center',show:false,operator:false  },
            { label: t('visit.ADDRESS'), prop: 'ADDRESS', align: 'center',show:false,operator:false  },
            { label: t('visit.POST'), prop: 'POST', align: 'center',show:false,operator:false  },
            { label: t('visit.TELEPHONE'), prop: 'TELEPHONE', align: 'center',show:false,operator:false  },
            { label: t('visit.FAX'), prop: 'FAX', align: 'center',show:false ,operator:false },
            { label: t('visit.EMAIL'), prop: 'EMAIL', align: 'center',show:false,operator:false  },
            { label: t('visit.NEXTVISITDT'), prop: 'NEXTVISITDT', align: 'center', render: 'datetime', sortable: 'custom', operator: 'RANGE', width: 160,show:false },
            { label: t('visit.SHAREFLAG'), prop: 'SHAREFLAG', align: 'center',show:false,operator:false  },
            { label: t('operate'), align: 'center', width: 100, render: 'buttons', buttons: optButtons, operator: false },
        ],
        dblClickNotEditColumn: [undefined, ],
        defaultOrder: { prop: 'VISITID', order: 'desc' },
    },
    {
        defaultItems: [],
    }
)

provide('baTable', baTable)

onMounted(() => {
    baTable.table.ref = tableRef.value
    baTable.mount()
    baTable.getIndex()?.then(() => {
        baTable.initSort()
        baTable.dragSort()
    })
})
</script>

<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
    name: 'visit',
})
</script>

<style scoped lang="scss"></style>
